# coding=UTF-8
from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
# from .models import Profile


class RegistrationForm(forms.ModelForm):
    """用户注册"""
    email = forms.EmailField(
        label=_('email'),
        widget=forms.TextInput,
    )
    password = forms.CharField(
        label=_('password'),
        widget=forms.PasswordInput,
    )
    password2 = forms.CharField(
        label=_('repeat password again'),
        widget=forms.PasswordInput,
    )

    class Meta:
        model = User
        # fields = ('username', 'email')
        fields = ('email', 'password', 'password2')

    def clean_password2(self):
        """
        密码一致校验
        """
        cd = self.cleaned_data
        if cd['password'] != cd['password2']:
            raise forms.ValidationError(_('inconsistent password'))
        return cd['password2']


